package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.service.SetmealService;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController("adminSetmealController")
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {


    @Autowired
    SetmealService setmealService;

    /*
    * 新增套餐
    * */
    @PostMapping
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐：{}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }
    /*
    * 分页查询
    * */
    @GetMapping("/page")
    public Result<PageResult> pageList(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询：{}",setmealPageQueryDTO);
        return Result.success(setmealService.pageList(setmealPageQueryDTO));
    }

    /*
    * 根据id查询套餐（包含套餐菜品数据）
    * */
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("根据id查询套餐：{}",id);
        return Result.success(setmealService.selectById(id));
    }

    /*
    * 根据id批量删除套餐
    * */
    @DeleteMapping
    public Result deleteByIds(@RequestParam(value = "ids") List<Long> ids){
        log.info("根据id批量删除套餐：{}", Arrays.toString(ids.toArray()));
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /*
    * 起售停售
    * */
    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Integer status,Long id){
        log.info("起售停售：id : {} status : {}",id,status);
        setmealService.changeStatus(status,id);

        return Result.success();
    }

    /*
    * 修改套餐
    * */
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐：{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }
}
